package com.jiaz.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;

/**
 * @author jiajiazi
 * @version 1.0
 * @date 2022/5/7 10:24
 */
@AllArgsConstructor
@NoArgsConstructor
public class ItemCheckInUser {

    private int venueId;

    private int[] checkInUser;


    public int getVenueId() {
        return venueId;
    }

    public void setVenueId(int venueId) {
        this.venueId = venueId;
    }

    public int[] getCheckInUser() {
        return checkInUser;
    }

    public void setCheckInUser(String checkInUser) {
        if (StringUtils.hasLength(checkInUser)) {
            String[] split = checkInUser.split(";");
            this.checkInUser = new int[split.length];
            for (int i = 0; i < split.length; i++) {
                this.checkInUser[i] = Integer.parseInt(split[i]);
            }
            return;
        }
        this.checkInUser = null;
    }

    public boolean include(int userId) {
        int beg = 0, end = checkInUser.length-1;
        while (beg <= end) {
            int mid = (beg + end) / 2;
            if (userId == checkInUser[mid]) {
                return true;
            } else if (userId < checkInUser[mid]) {
                end = mid - 1;
            } else {
                beg = mid + 1;
            }
        }
        return false;
    }
}
